
#ifndef __SYSTASK_H
#define	__SYSTASK_H

#include <stdint.h>
#include "dataproc.h"
#include "pulse.h"
#include "rtctime.h"
#include "mytype.h"
#include "iohandle.h"
#include "app_def.h"

#ifdef	__cplusplus
extern "C" {
#endif
	
#ifdef   _SYSTASK_MODULE_
#define  MY_EXT
#else
#define  MY_EXT  extern
#endif  

typedef struct
{
    uint32_t st;
} sys_info_type;

typedef struct 
{
    volatile uint32_t u_tick;
    volatile uint32_t powerup_time_cnt;
    volatile uint32_t clks_at_event_rcv;
        
    timer_pulse_type pulse;
    sig_time_type sig_time;
    TIME_Type rtc_time;
    TIME_Type rtc_time_local;
    uint32_t local_rtc_err_cnt;
    uint8_t b_rtc_on_back_req;
    uint16_t back_on[2];
    
    led_breath_type led_obj;
    volatile uint8_t b_coremark;
    uint32_t exe_time_us;
    uint32_t exe_time_us_max;
    
    io_flt_type key;
    io_signal_type key_info;
    
    uint16_t local_rtc_on_req_old;
    struct 
    {
        uint16_t run_st;
        uint16_t run_st_old;
        uint16_t ut;
        uint16_t ut_old;
        uint16_t ut_cnt;
        
        sig_time_type time_old;
        uint32_t save_cnt;
        uint8_t clr_req;
        
        sig_time_type time_hist_powerup;
    } hist_opt;
    
    hist_head_type hist_head;
    hist_mid_type hist_mid;
    hist_tail_type hist_tail;
    
    io16_simp_flt_type in;
    
    struct
    {
        volatile uint32_t crc_val;
        uint32_t clk_ahb;
        uint32_t clk_apb1;
        uint32_t clk_apb2;
        uint32_t clk_adc;
        uint32_t clk_sys;
        uint8_t rtc_sim_init;
    } dbg;
    
    struct
    {
        uint8_t err_st;
        uint8_t err_no_file_found;
        uint8_t err_crc;
        uint8_t err_sum;
        uint8_t err_app_same;
        
        volatile uint8_t update_ok;
        uint32_t version_old;
        uint32_t version_new;
        uint32_t time_old;
        uint32_t time_new;
    } update_info;
    
    struct
    {
        uint8_t usb_ran_save;
        uint8_t ext_led_flash_delay;
        volatile uint8_t flash_clr_st;
    } led_req;
    
    struct
    {
        struct
        {
            uint32_t buad;
            uint8_t  mb_id;
            uint8_t  fo;
        } com1;
        
        struct
        {
            uint32_t buad;
            uint8_t  mb_id;
            uint8_t  fo;
        } com2;
        
        char  dev_type[24];
        char  dev_id[32];
        char  usr_type[32];
        char  usr_id[24];
        
        int32_t password;
        uint8_t out_encode;
        uint32_t save_cnt;
    } sys_cfg;
    char ver_cfg[8];
    
    volatile char sys_save_req;
    
} sys_run_st_type;

MY_EXT sys_run_st_type sys_st;


void sys_cfg_load(void);
void sys_cfg_save(void);

#undef MY_EXT

#ifdef	__cplusplus
}
#endif

#endif	/* __SYSTASK_H */
